package com.cn.demo.springboot.controller;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.cn.demo.springboot.shiro.annotation.MenuEx;
import com.cn.demo.springboot.shiro.service.IAuthRealmService;
import com.cn.demo.springboot.vo.PageRequest;

@Controller
@RequestMapping("/authorization")
public class AuthorizationController {
	
	@Autowired
	private IAuthRealmService authRealmService;
	
	//@MenuEx(code = "showRole" ,parentCd = "",name = "角色列表")
	//@RequiresPermissions("/showRole")
	@RequestMapping("showRole")
	public ModelAndView showRole(PageRequest PageRequest) {
		return new ModelAndView("authorization/showRole").addObject("roles", authRealmService.findRoleAll());
	}
	
	
	@RequestMapping("addRole")
	@ResponseBody
	public String addRole(String roleName) {
		 authRealmService.addRole(roleName);
		 return "success";
	}
	
/*	@RequiresPermissions("/permissionManager")
	@MenuEx(code = "permissionManager" ,parentCd = "showRole",name = "权限管理")*/
	@RequestMapping("/permissionManager")
	public ModelAndView permissionManager(Integer roleId) {
		return new ModelAndView().addObject("permissionAll", authRealmService.findPermissionAll())
				.addObject("currentUserPermission", authRealmService.findPermissionByRole(roleId));
	}
	
}
